package tech.gismap.admin.web;

import cn.dev33.satoken.annotation.SaIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import tech.gismap.admin.service.DeepSeekStreamingService;

@RestController
@RequestMapping("/api/ai")
public class ChatSseController {

    @Autowired
    private DeepSeekStreamingService streamingService;

    @SaIgnore
    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter stream(@RequestParam("prompt") String prompt) {
        SseEmitter emitter = new SseEmitter(0L); // 永不超时
        streamingService.streamChat(prompt, emitter);
        return emitter;
    }
}
